package com.taillive.commons;

public class FormatUtils {

	
	/**
	 * 
	 * @param i
	 * @param length
	 * @param leadingChar
	 * @return
	 */
	public static String i2s(int i, int length, char leadingChar) {

		StringBuffer buf = new StringBuffer();
		for (int j = 0; j < length - ConvertUtils.i2s(i).length(); j++) {
			buf.append(leadingChar);
		}

		buf.append(i);
		String s = new String(buf);
		buf.setLength(0);
		buf = null;
		return s;
	}
	
	
	/**
	 * 
	 * @param i
	 * @param length
	 * @return
	 */
	public static String i2s(int i, int length) {
		return i2s(i, length, '0');
	}

	public static String i2s(long i, int length) {
		return l2s(i, length, '0');
	}
	
	public static String l2s(long i, int length, char leadingChar) {

		StringBuffer buf = new StringBuffer();
		for (int j = 0; j < length - ConvertUtils.l2s(i).length(); j++) {
			buf.append(leadingChar);
		}

		buf.append(i);
		String s = new String(buf);
		buf.setLength(0);
		buf = null;
		return s;
	}

}
